package com.tim.app.ui.adapter.personal;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.application.library.widget.recycle.BaseRecyclerAdapter;
import com.tim.app.R;
import com.tim.app.server.entry.Answer;

import java.util.List;


/**
 * 浏览记录
 */
public class AnswerBrowseHistoryAdapter extends BaseRecyclerAdapter<BaseRecyclerAdapter.BaseRecyclerViewHolder, Answer> {

    private Context mContext;


    public AnswerBrowseHistoryAdapter(Context mContext, List<Answer> mDataList) {
        super(mDataList);
        this.mContext = mContext;
    }

    @Override
    public BaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        BaseRecyclerViewHolder holder = null;
        holder = new InfoViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.cell_answer_browser_history, parent, false));
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseRecyclerViewHolder mHolder, int position, Answer data) {
        if (data == null) {
            return;
        }
        InfoViewHolder holder = (InfoViewHolder) mHolder;
        holder.ivBrowserHistoryIcon.setBackgroundResource(R.drawable.ic_answer_history);
        if (!TextUtils.isEmpty(data.getProblemTitle())) {
            holder.tvHisoryTitle.setText(data.getProblemTitle());
        }
        if (!TextUtils.isEmpty(data.getContent())) {
            holder.tvHisoryContent.setText(data.getContent());
        }
        if (position == getDataList().size() - 1) {
            holder.vLine.setVisibility(View.GONE);
        } else {
            holder.vLine.setVisibility(View.VISIBLE);
        }
    }

    public class InfoViewHolder extends BaseRecyclerViewHolder {

        ImageView ivBrowserHistoryIcon;
        TextView tvHisoryTitle;
        TextView tvHisoryContent;
        View vLine;

        public InfoViewHolder(View itemView) {
            super(itemView);
            ivBrowserHistoryIcon = (ImageView) itemView.findViewById(R.id.ivBrowserHistoryIcon);
            tvHisoryTitle = (TextView) itemView.findViewById(R.id.tvHisoryTitle);
            tvHisoryContent = (TextView) itemView.findViewById(R.id.tvHisoryContent);
            vLine = itemView.findViewById(R.id.vLine);
        }

    }

}
